package com.jokins.admin.ios.articles.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.jokins.admin.ios.articles.param.BookArticlesParam;
import com.jokins.admin.ios.articles.param.SaveBookArticlesParam;
import com.jokins.admin.ios.articles.service.BookArticlesService;
import com.jokins.admin.ios.articles.vo.BookArticlesListVo;
import com.jokins.common.util.ResultData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 〈book 交流发布文章〉<br>
 *
 * @author Mr.Wang
 * @create 2025/2/6
 */
@RestController
@RequestMapping("ios/articles")
public class BookArticlesController {

    @Autowired
    private BookArticlesService articlesService;

    @GetMapping("/getArticlesList")
    public ResultData getArticlesList(BookArticlesParam param) {
        param.setPageSize(3);
        final Page<Object> page = PageHelper.startPage(param.getCurrentPage(), param.getPageSize(), true);
        List<BookArticlesListVo> userList = articlesService.getArticlesList(param);
        return ResultData.pageResponse(userList, page.getTotal(), page.getPages(), page.getPageNum());
    }

    @PostMapping("/save")
    public ResultData saveArticles(@RequestBody SaveBookArticlesParam param) {
        articlesService.saveArticles(param);
        return new ResultData("发布成功！");
    }
}